function [v Z] = parcellfun_ (varargin)

   ## usage:  [v Z] = parcellfun_ (varargin)
   ##
   ## wrapper for parcellfun

   pkg load parallel
   global PAR NCPU

   # [desc, flag] = pkg ("describe", "all") ;
   # pkg unload all ; pkg load general

   if isfield(PAR, "ncpu"), NCPU = PAR.ncpu ; endif

   if isempty(NCPU) || NCPU == 0 || (isfield(PAR, "dbg") && PAR.dbg)
      if !isempty(j = find(strcmpi(varargin, "verboselevel")))
	 varargin = [varargin(1:j-1) varargin(j+2:end)] ;
      endif
      if nargout == 2
	 [v Z] = cellfun(varargin{:}) ;
      else
	 v = cellfun(varargin{:}) ;
      endif 
   else
      if nargout == 2
	 [v Z] = parcellfun(NCPU, varargin{:}, "ErrorHandler", @errfun) ;
      else
	 v = parcellfun(NCPU, varargin{:}, "ErrorHandler", @errfun) ;
      endif 
   endif 

   # for j = 1:length(flag)
   #    if strcmp(flag{j}, "Loaded")
   # 	 pkg("load", desc{j}.name) ;
   #    else
   # 	 pkg("unload", desc{j}.name) ;
   #    endif 
   # endfor 

endfunction


function varargout = errfun (S, varargin)

   ## usage:  varargout = errfun (S, varargin)
   ##
   ## ErrorHandler

   for j = 1:nargout
      varargout{j} = nan ;
   endfor

   warning(S.identifier, S.message) ;

endfunction
